import { query } from '$lib/config/db';

const permissionsModule = {
  getById: async (id) => {
    const sql = 'SELECT r.id AS role_id, r.name AS role_name, r.description AS role_desc, p.id AS permission_id, p.name AS permission_name, p.handle AS permission_handle, p.icon, p.sort, p.parent_id FROM roles r JOIN role_permission rp ON rp.role_id = r.id JOIN permissions p ON p.id = rp.permission_id WHERE r.id = $1 ORDER BY p.sort ASC';
    const params = [id];
    const rows = await query(sql, params);
    return rows[0];
  }
}

export default permissionsModule;